/*
 *    Copyright (c) 2018-2025, boss All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the boss developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: boss
 */
package com.hopes.bizz.risk.imei.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hopes.bizz.risk.imei.entity.EquipmentImeiEntity;
import com.hopes.bizz.risk.imei.mapper.EquipmentImeiMapper;
import com.hopes.bizz.risk.imei.service.EquipmentImeiService;
import org.springframework.stereotype.Service;

/**
 * 设备绑定imei码
 *
 * @author pig
 * @date 2023-08-18 11:06:49
 */
@Service
public class EquipmentImeiServiceImpl extends ServiceImpl<EquipmentImeiMapper, EquipmentImeiEntity> implements EquipmentImeiService {


    @Override
    public void deleteAndSave(EquipmentImeiEntity equipmentImei) {
        // 查看IMEI码是否存在
        EquipmentImeiEntity equipmentImeiEntity = getOne(Wrappers.lambdaQuery(EquipmentImeiEntity.class)
                .eq(EquipmentImeiEntity::getImei, equipmentImei.getImei())
        );
        if(ObjectUtil.isNotEmpty(equipmentImeiEntity)){
            // 删除旧的绑定关系
            removeById(equipmentImeiEntity);
        }
        // 保存新的绑定关系
        save(equipmentImei);
    }
}
